//
//  ResetPassWordViewController.m
//  GoodWayClient
//
//  Created by HuiDong on 15/12/21.
//  Copyright © 2015年 HuiDong. All rights reserved.
//

#import "ResetPassWordViewController.h"
#import "Constant.h"
#import "AFNetworking.h"

@interface ResetPassWordViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *iphone;
@property (weak, nonatomic) IBOutlet UITextField *pad;
@property (weak, nonatomic) IBOutlet UITextField *code;
- (IBAction)backing:(id)sender;

@end

@implementation ResetPassWordViewController

- (void)viewDidLoad
{
    self.iphone.delegate = self;
    self.pad.delegate = self;
    self.code.delegate = self;
}

//发送验证码
- (IBAction)sendCode:(id)sender {
    //网络请求
    AFHTTPRequestOperationManager *request = [AFHTTPRequestOperationManager manager];
    request.responseSerializer = [AFJSONResponseSerializer serializer];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"phone"] = self.iphone.text;
    
    [request POST:[NSString stringWithFormat:@"%@%@",url1,@"ForgetSMS"] parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = (NSDictionary *)responseObject;
        if ([[NSString stringWithFormat:@"%@",dic[@"Status"]] isEqualToString:@"0"]) {
            [[[UIAlertView alloc] initWithTitle:@"提示" message:@"验证码发送成功!" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
        }else
        {
            [[[UIAlertView alloc] initWithTitle:@"提示" message:dic[@"Message"] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"系统网络申请错误!");
    }];
}
//重置
- (IBAction)reset:(id)sender {
    //网络请求
    AFHTTPRequestOperationManager *request = [AFHTTPRequestOperationManager manager];
    request.responseSerializer = [AFJSONResponseSerializer serializer];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"phone"] = self.iphone.text;
    dic[@"password"] = self.pad.text;
    dic[@"smscode"] = self.code.text;
    
    [request POST:[NSString stringWithFormat:@"%@%@",url1,@"ForgetPwd"] parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic = (NSDictionary *)responseObject;
        if ([[NSString stringWithFormat:@"%@",dic[@"Status"]] isEqualToString:@"0"]) {
            [[[UIAlertView alloc] initWithTitle:@"提示" message:@"注册成功!" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
            [self performSelector:@selector(back) withObject:nil afterDelay:1.0f];
        }else
        {
            [[[UIAlertView alloc] initWithTitle:@"提示" message:dic[@"Message"] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil] show];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"系统网络申请错误!");
    }];
    
}

- (void)back
{
    [self dismissViewControllerAnimated:YES completion:nil];
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.view endEditing:YES];
    return YES;
}
- (IBAction)backing:(id)sender {
    [self back];
}
@end
